;;(load "ut.scm")
;;(load "match.scm")
(define (rd-match s m n c in)
  (let ((len (string-length s))
        )
    (cond
     ((>= n len)
      (err-msg "[~a]rd-match：[~a]中未匹配到指定字符[~a]。" n (substring s m len) c)
       #f)
      ((char=? c (string-ref s n))
       (if in
           (substring s m (+ n 1))
           (substring s m n)))
      ((< n len)
       (rd-match s m (+ n 1) c in))
      (else (err-msg "[~a]rd-match2-slash:can't reach here." n)
	    #f))))
(define (rd-match-slash s m n c in)
  (let ((len (string-length s))
        )
    (cond
     ((>= n len)
      (err-msg "[~a]rd-match-slash：[~a]中未匹配到指定字符[~a]。" n (substring s m len) c)
       #f)
      ((and (< (+ n 1) len)(char=? (string-ref s n) #\\))
       (rd-match-slash s m (+ n 2) c in))
      ((char=? c (string-ref s n))
       (if in
           (substring s m (+ n 1))
           (substring s m n)))
      ((< n len)
       (rd-match-slash s m (+ n 1) c in))
      (else (err-msg "[~a]rd-match-slash:can't reach here." n)
	    #f))))
(define (rd-match-in s n c)(rd-match s n n c #t))
(define (rd-match-not s n c)(rd-match s n n c #f))
(define (rd-match-slash-in s n c)(rd-match-slash s n n c #t))
(define (rd-match-slash-not s n c)(rd-match-slash s n n c #f))
(define (rd-match2 s m n c1 c2 in)
  (let ((len (string-length s))
        )
    (cond
     ((>= n len)
      (err-msg "[~a]rd-match2：[~a]中未匹配到指定连续字符[~a][~a]。" n (substring s m len) c1 c2)
       #f)
      ((and (< (+ n 1) len)(char=? c1 (string-ref s n))(char=? c2 (string-ref s (+ n 1))))
       (if in
           (substring s m (+ n 2))
           (substring s m n)))
      ((< n len)
       (rd-match2 s m (+ n 1) c1 c2 in))
      (else (err-msg "[~a]rd-match2:can't reach here." n)
	    #f))))
(define (rd-match2-slash s m n c1 c2 in)
  (let ((len (string-length s))
        )
    (cond
     ((>= n len)
      (err-msg "[~a]rd-match2-slash：[~a]中未匹配到指定连续字符[~a][~a]。" n (substring s m len) c1 c2)
       #f)
      ((and (< (+ n 1) len)(char=? (string-ref s n) #\\))
       (rd-match2-slash s m (+ n 2) c1 c2 in))
      ((and (< (+ n 1) len)(char=? c1 (string-ref-s n))(char=? c2 (string-ref s (+ n 1))))
       (if in
           (substring s m (+ n 2))
           (substring s m n)))
      ((< n len)
       (rd-match2-slash s m (+ n 1) c1 c2 in))
      (else (err-msg "[~a]rd-match2-slash:can't reach here." n)
	    #f))))
(define (rd-match2-in s n c1 c2)(rd-match2 s n n c1 c2 #t))
(define (rd-match-list s m n l in)
  (let ((len (string-length s))
        )
    (cond
     ((>= n len)
      (err-msg "[~a]rd-match-list：[~a]中未匹配到指定列表的字符[~a]。" n (substring s m len) l)
      #f)
      ((member (string-ref s n) l)
       (if in
           (substring s m (+ n 1))
           (substring s m n)))
      ((< n len)
       (rd-match-list s m (+ n 1) l in))
      (else (err-msg "[~a]rd-match-list:can't reach here." n)
	    #f))))
(define (rd-match-newline s m n)
  (let ((len (string-length s))
	(k (+ n 1))
	)
    (cond
     ((>= k len)
      #f)
     ((and (char=? (string-ref s n) #\newline) (not (member (string-ref s k) cyl-deli-list)))
      (substring s m k))
     ((< k len)
      (rd-match-newline s m k)))))
(define (string-unit c s)
  (member c (string->list s)))
(define (string-member cs s)
  (call/cc (lambda (abort)
	     (let ((l (string-length cs))(len (string-length s)))
	       (tr-string (i c s 0)
			  (if (char=? (string-ref cs 0) c)
			      (if (and (<= (+ i l) len)(string=? cs (substring s i (+ i l))))
				  (abort #t))))
	       #f))))
				    
				  
    
